package agents;

import interfaces.AgentInterface;

import interfaces.WorldInterface;
import interfaces.impl.Agent;

import java.awt.Graphics;
import java.util.ArrayList;

import actions.ActionAttack;

import constants.*;
import factoryNCastle.SpetialFeatureFactory;


import objects.SpetialFeature;
import objects.WorldObject;
import universe.Universe;

public class AgentAttackClosestObject extends Agent implements AgentInterface{
	
	private int idObjtectToSearch = Constants.OBJECT_REFERENCE_SUGAR;
	
	private double attackTime=0;
	private ActionAttack actionAttack;
	

	public AgentAttackClosestObject (){
		this.id=Constants.AGENT_ATTACK_CLOSEST_OBJECT;
		priority=1; //i used now but i have to change this
		actionAttack= new ActionAttack( priority);
		actionAttack.setExecuteTime(1000);
		actionAttack.setWaitTimeToExecute(2000);
		//i set the list of spetial features needed
			
		
	}
	
	@Override
	public void update(WorldObject object, Universe world, double time) {
		
		if(!canUpdate(object)){
			return;
		}
		
		attackTime=attackTime+time;
		
		if(attackTime>=100){
			//attackTime=listSpetialFeatures.get(6).getValue();
			attackTime=100;
		}
		
		int visionRange=5;
		
		ArrayList<WorldObject> list = world.getObjects(object.getPosition().getX()-visionRange, object.getPosition().getY()-visionRange,
				object.getPosition().getX()+visionRange,object.getPosition().getY()+visionRange,idObjtectToSearch);
		if(list.isEmpty()){
			return;
		}
		//TODO i search closest but i will do it later, now i jut serach the first
		
		WorldObject target = list.get(0);
		
//		System.out.println("Encontre un tarro de azucar");
		
		
		
	}

	@Override
	public void paint(Graphics g, WorldObject object) {
		
		return;
		
	}

	@Override
	public String getName() {
		return "Atacar";
	}

	@Override
	public void setName(String name) {
		// TODO Auto-generated method stub
		this.name=name;
	}

}
